﻿using EFEntity;
using System;
using System.Collections.Generic;
using System.Text;
using Model;
using System.Threading.Tasks;
using System.Linq;
using Iservices;

namespace Services
{
   public class engage_major_releaseServices:Iengage_major_releaseServices
    {
        private readonly MyDbContext myDBContext;

        public engage_major_releaseServices(MyDbContext myDBContext)
        {
            this.myDBContext = myDBContext;
        }

        public async Task<List<engage_major_release>> FenYe(FenYe fy)
        {
            var data = myDBContext.engage_major_release.OrderBy(e => e.mre_id).ToList();
            fy.Rows = data.Count();
            fy.Pages = (fy.Rows - 1) / fy.PageSize + 1;
            List<Eengage_major_release> list = new List<Eengage_major_release>();
            await Task.Run(() =>
            {
                list = data.Skip((fy.CurrentPage - 1) * fy.PageSize)
                    .Take(fy.PageSize)
                    .ToList();
            });
            //把EO-DTO
            List<engage_major_release> list2 = new List<engage_major_release>();
            foreach (Eengage_major_release item in list)
            {
                engage_major_release t = new engage_major_release()
                {
                    mre_id = item.mre_id,
                    first_kind_id = item.first_kind_id,
                    first_kind_name = item.first_kind_name,
                    second_kind_id = item.second_kind_id,
                    second_kind_name = item.second_kind_name,
                    third_kind_id = item.third_kind_id,
                    third_kind_name = item.third_kind_name,
                    major_kind_id = item.major_kind_id,
                    major_kind_name = item.major_kind_name,
                    major_id = item.major_id,
                    major_name = item.major_name,
                    human_amount = item.human_amount,
                    engage_type = item.engage_type,
                    deadline = item.deadline,
                    register = item.register,
                    changer = item.changer,
                    regist_time = item.regist_time,
                    change_time = item.change_time,
                    major_describe = item.major_describe,
                    engage_required = item.engage_required
                };
                list2.Add(t);
            }
            return list2;
        }

        //查看全部
        public async Task<List<engage_major_release>> ngage_major_releaseSelect()
        {
            List<Eengage_major_release> list = new List<Eengage_major_release>();
            await Task.Run(() =>
            {
                list = myDBContext.engage_major_release.ToList();
            });

            //Automap
            List<engage_major_release> list2 = new List<engage_major_release>();
            foreach (Eengage_major_release item in list)
            {
                engage_major_release t = new engage_major_release()
                {
                       mre_id =item.mre_id,
	first_kind_id  =item.first_kind_id,                                                             
 	first_kind_name    =item.first_kind_name,                                                       
 	second_kind_id      =item.second_kind_id,                                                
 	second_kind_name    =item.second_kind_name,                                                        
 	third_kind_id      =item.third_kind_id,                                                       
	third_kind_name   =item.third_kind_name,                                                     
	major_kind_id        =item.major_kind_id,                                                   
 	major_kind_name      =item.major_kind_name,                                                     
	major_id           =item.major_id,                                                      
    major_name         =item.major_name,                                                      
 	human_amount    =item.human_amount,                                                            
	engage_type       =item.engage_type,                                                          
 	deadline          =item.deadline,                                                      
 	register          =item.register,                                      
changer              =item.changer,                                              
regist_time         =item.regist_time,                                                 
 	change_time =item.change_time,
	major_describe     =item.major_describe,                                                           
	engage_required =item.engage_required
                };
                list2.Add(t);
            }
            return list2;
        }

    }
}
